
package com.xiaoma.myaudience.biz.activity;

import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;

import com.xiaoma.myaudience.R;
import com.xiaoma.myaudience.biz.app.AudienceApplication;
import com.xiaoma.myaudience.biz.util.VideoPrefHelper;
import com.xiaoma.myaudience.util.SystemUtils;
import com.xiaoma.myaudience.util.activity.BasePreferenceActivity;

public class SettingActivity extends BasePreferenceActivity implements View.OnClickListener{    
    private List<ResolveInfo> mShareList;

    private BroadcastReceiver mLoginReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            onLoginChanged();
        }
    };
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        addPreferencesFromResource(R.xml.setting);
        setNetEaseTitleBarVisibility(View.VISIBLE);
        setNetEaseTitle(R.string.setting_title);
        setNetEaseTitleGravity(Gravity.CENTER);
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * 初始化设置界面
     */
    private void initSettings() {
        // 初始化
        mShareList = SystemUtils.getShareTargets(this, "message/rfc822");
        
        onLoginChanged();

    }
    
    private void onLoginChanged() {
        boolean isLogin = ((AudienceApplication) getApplication()).isLogin();

        Button login = (Button) findViewById(R.id.login_bt);
        login.setVisibility(isLogin ? View.GONE : View.VISIBLE);

        // 当是未登录时 disabled
        CheckBoxPreference checkBoxPref = (CheckBoxPreference) findPreference(VideoPrefHelper.PREF_KEY_PLAY_RECORD_SYNC);
        checkBoxPref.setEnabled(isLogin);

        checkBoxPref = (CheckBoxPreference) findPreference(VideoPrefHelper.PREF_KEY_SUBSCRIBE_SYNC);
        checkBoxPref.setEnabled(isLogin);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.login_bt:
                Intent intent = new Intent(this, LoginActivity.class);
                startActivity(intent);
                break;

            default:
                break;
        }
        
    }
}
